home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / timer.h < prev    next >
C/C++ Source or Header  |  1994-07-11  |  1KB  |  39 lines

  1. /* Software timers
  2.  * There is one of these structures for each simulated timer.
  3.  * Whenever the timer is running, it is on a doubly-linked list
  4.  * pointed to by "timers" so that the (hardware) timer interrupt
  5.  * can quickly run through the list and change counts and states.
  6.  * Stopping a timer or letting it expire causes it to be removed
  7.  * from the list; starting a timer puts it on the list.
  8.  */
  9. struct timer {
  10.     struct timer *next;    /* Doubly-linked-list pointers */
  11.     struct timer *prev;
  12.     int32 start;        /* Period of counter (load value) */
  13.     int32 count;        /* Ticks to go until expiration */
  14.     void (*func)();        /* Function to call at expiration */
  15.     char *arg;        /* Arg to pass function */
  16.     char state;        /* Timer state */
  17. #define    TIMER_STOP    0
  18. #define    TIMER_RUN    1
  19. #define    TIMER_EXPIRE    2
  20. };
  21. #define    NULLTIMER    (struct timer *)0
  22. #define    MAX_TIME    (int32)4294967295    /* Max long integer */
  23. #ifndef MSPTICK
  24. #if    ATARI_ST && (!MWC)
  25. #define    MSPTICK        100        /* Milliseconds per tick */
  26. #else
  27. #define    MSPTICK        55        /* Milliseconds per tick */
  28. #endif
  29. #if    defined(NOMAD)
  30. #undef    MSPTICK
  31. #define    MSPTICK        1000        /* one second per tick */
  32. #endif
  33. #endif
  34. /* Useful user macros that hide the timer structure internals */
  35. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  36. #define    dur_timer(t)    ((t)->start)
  37. #define    read_timer(t)    ((t)->count)
  38. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  39.